package zucc.edu.cn.chengchengparttime.Home;

import android.app.Fragment;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.appcompat.widget.AppCompatButton;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import java.util.ArrayList;
import java.util.List;

import zucc.edu.cn.chengchengparttime.Home.HomeAdapter;
import zucc.edu.cn.chengchengparttime.R;
import zucc.edu.cn.chengchengparttime.Text;

public class HomeFragment extends Fragment {
    private RecyclerView rv; //RecyclerView布局
    private HomeAdapter homeAdapter; //适配器
    private Context context;
    private List<Text> data=new ArrayList<>(); //数据列表
    private EditText editText;
    private TextView search;

    public HomeFragment() {}

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_home, container, false);
        context = this.getActivity();
        rv = view.findViewById(R.id.rv);

        Text t=new Text("图书馆图书整理","浙大城市学院图书馆","每周一至周五","15/小时","月结");
        data.add(t);
        Text t2=new Text("体测工作人员","浙大城市学院体育室","周一18:00-19:00","16/小时","月结");
        data.add(t2);
        Text t3=new Text("图书馆图书整理2","浙大城市学院图书馆","每周二至周五","15/小时","月结");
        data.add(t3);
        Text t4=new Text("图书馆图书整理3","浙大城市学院图书馆","每周一至周五","17/小时","月结");
        data.add(t4);
        Text t5=new Text("图书馆图书整理4","浙大城市学院图书馆","每周四至周五","18/小时","月结");
        data.add(t5);
        Text t6=new Text("图书馆图书整理5","浙大城市学院图书馆","每周一至周五","19/小时","月结");
        data.add(t6);

        //适配器的定义与设置
        homeAdapter=new HomeAdapter(data,context);
        LinearLayoutManager linearLayoutManager=new LinearLayoutManager(this.getActivity());
        linearLayoutManager.setOrientation(RecyclerView.VERTICAL);
        rv.setLayoutManager(linearLayoutManager);
        rv.setAdapter(homeAdapter);

        editText=view.findViewById(R.id.search);
        editText.setOnClickListener(view1 -> {
            Toast.makeText(this.context, "点击了搜索兼职输入框" , Toast.LENGTH_SHORT).show();
        });

        search=view.findViewById(R.id.textsearch);
        search.setOnClickListener(view1 -> {
            Toast.makeText(this.context, "点击了搜索兼职" , Toast.LENGTH_SHORT).show();
            //关闭手机的键盘
            InputMethodManager imm=(InputMethodManager) view1.getContext().
                    getSystemService(Context.INPUT_METHOD_SERVICE);
            if (imm.isActive()) {
                imm.hideSoftInputFromWindow(view1.getApplicationWindowToken(),0 );
            }
            //输入框内容进行模糊查询

            //输入框内容清空
            editText.setText("");
        });
        return view;
    }
}
